package com.hc.fdkforwarders.service;

import com.hc.fdkforwarders.common.Result;
import com.hc.fdkforwarders.dao.SellerFetchOrderDao;
import com.hc.fdkforwarders.service.fegin.client.ForwardersApi;
import com.hc.fdkforwarders.vo.GoodsScannedVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;

@Service
public class GoodsScannedService {

    @Resource
    private SellerFetchOrderDao sellerFetchOrderDao;
    @Autowired
    ForwardersApi forwardersApi;

    public GoodsScannedVO goodsScanned(String barcode){
        GoodsScannedVO goodsScannedVO = sellerFetchOrderDao.goodsScanned(barcode);
        String message;
        boolean success;
        if(goodsScannedVO.getStatus() == 3){
            message = "小标签重复扫描，不能重复到货确认";
            success = false;
        }else{
            message = "商品到货";
            success = true;
            sellerFetchOrderDao.updateStatus(barcode, new Byte("3"));
        }

        goodsScannedVO.setMessage(message);
        goodsScannedVO.setSuccess(success);
        Long skuId = goodsScannedVO.getSkuId();
        forwardersApi.goodsScanned(skuId);
        return goodsScannedVO;


    }
}
